﻿

namespace Mulala.Cavan.Presentation.Mvc.Controller
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.Mvc;
    using Mulala.Cavan.Application.MainBoundedContext.LogModule;
    using Mulala.Cavan.Domain.MainBoundedContext.LogModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Presentation.Mvc.ViewModel;
    using Mulala.Cavan.Presentation.Seedwork;

    public class VisitHistoryController : EntityController<VisitHistory, VisitHistorySearch, IVisitHistoryViewModel, IVisitHistoryAppService>, IVisitHistoryController
    {
        public override string ControllerName
        {
            get { return ControllerConst.VISITHISTORY; }
        }

        public override bool UseDenied
        {
            get { return false; }
        }

        public VisitHistoryController()
        {
            this.Model = ModelFactory.CreateModel<IVisitHistoryViewModel>();
        }

        [ActionName("recentvisitor")]
        [ChildActionOnly]
        public ActionResult GetRecentVisitors(int id)
        {
            VisitHistorySearch visitHistorySearch = VisitHistorySearchFactory.CreateVisitHistorySearch(id);
            long total = 0;
            IList<VisitHistory> visitHistories = this.AppService.GetBySearch(visitHistorySearch, out total).ToList();
            IVisitHistorysViewModel visitHistoriesViewModel = ModelFactory.CreateModel<IVisitHistorysViewModel>();
            IList<IVisitHistoryViewModel> visitHistoryViewModels = VisitHistoryViewModelConverter.Convert(visitHistories);
            visitHistoriesViewModel.Visitors = visitHistoryViewModels;

            return PartialView("~/Views/VisitHistory/_recentVisitorPartial.cshtml", visitHistoriesViewModel);
        }
    }
}
